home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
util
/
time
/
backclock.lha
/
BackClock
/
sources
/
conf.c
next >
Wrap
C/C++ Source or Header
|
1999-01-10
|
5KB
|
171 lines
/*****************************************************************************
*
* name : conf.c
* description : load & save prefs file
* version : 1.2
*
* created : 08-03-98
* last change : 10-01-99
*
* version:
* 1.0 : initial
* 1.1a: minor fix
* 1.1b: Default configuration fixed
* 1.1c: minor change
* 1.2 : added support for new options (shadows and middle point)
*****************************************************************************
*/
#include <dos/dos.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <string.h>
#include "utils.h"
#include "conf.h"
#include "obp.h"
void SaveEnv(idWin * prj, BOOL envarc) {
UBYTE * txtform = NULL ;
if (!SaveConf(prj, CF_NAMEENV)) {
/* error during saving
*/
if (txtform = AllocVec(100, MEMF_PUBLIC|MEMF_CLEAR)) {
/* open an info request
*/
strcat(txtform, ERR_ENV) ;
Fault(prj->lastError, ERR_ENV, txtform, 100) ;
ez_req("BackClock request", txtform, "Continue", &(prj->lastError)) ;
FreeVec(txtform) ;
}
}
if (envarc) {
if (!SaveConf(prj, CF_NAMEENVARC)) {
/* error during saving
*/
if (txtform = AllocVec(100, MEMF_PUBLIC|MEMF_CLEAR)) {
/* open an info request
*/
strcat(txtform, ERR_ENVARC) ;
Fault(prj->lastError, ERR_ENVARC, txtform, 100) ;
ez_req("BackClock request", txtform, "Continue", &(prj->lastError)) ;
FreeVec(txtform) ;
}
}
}
}
BOOL SaveConf(idWin * prj, UBYTE * fl_name) {
struct ConfFile cf_save ;
ULONG file ;
BOOL ret=FALSE ;
int i ;
CopyMem("BACK", cf_save.id, 4) ;
cf_save.posX = prj->backWin.posX ;
cf_save.posY = prj->backWin.posY ;
cf_save.lenX = prj->backWin.width ;
cf_save.lenY = prj->backWin.height ;
for(i = 0; i<NUM_COLORS; i++)
CopyMem(&(prj->backWin.cmap[i]), &(cf_save.cmap[i]), sizeof(struct RGB)) ;
cf_save.cmap[COL_BLA].R = 0 ;
cf_save.cmap[COL_BLA].G = 0 ;
cf_save.cmap[COL_BLA].B = 0 ;
cf_save.filln = prj->backWin.filln ;
cf_save.fill = prj->backWin.fill ;
cf_save.drawsec = prj->backWin.drawsec ;
cf_save.drawsha = prj->backWin.drawsha ;
cf_save.drawmpo = prj->backWin.drawmpo ;
if (cf_save.fill !=0) cf_save.fill = -1 ;
if (file = Open(fl_name, MODE_NEWFILE)) {
Write(file, &cf_save, sizeof(struct ConfFile)) ;
Close(file) ;
prj->lastError = OK ;
ret=TRUE ;
}else prj->lastError = IoErr() ;
return ret ;
}
BOOL LoadConf(idWin * prj) {
/* Reload configuration file
*/
struct ConfFile cf_load ;
ULONG file ;
BOOL ret = FALSE ;
int i ;
prj->lastError = IoErr() ;
prj->backWin.posX = 0 ;
prj->backWin.posY = prj->wb->BarHeight ;
prj->backWin.width = 100 ;
prj->backWin.height = 100 ;
prj->backWin.cmap[COL_SEC].reg = (UBYTE)getPen(prj, 0, 100, 200) ;
prj->backWin.cmap[COL_MIN].reg = (UBYTE)getPen(prj, 255, 0, 0) ;
prj->backWin.cmap[COL_HEU].reg = (UBYTE)getPen(prj, 0, 255, 0) ;
prj->backWin.cmap[COL_TIC].reg = (UBYTE)getPen(prj, 0, 0, 255) ;
prj->backWin.cmap[COL_BAC].reg = (UBYTE)getPen(prj, 0, 0, 0) ;
prj->backWin.cmap[COL_MPO].reg = (UBYTE)getPen(prj, 0, 0, 0) ;
prj->backWin.cmap[COL_BLA].reg = (UBYTE)getPen(prj, 0, 0, 0) ;
prj->backWin.cmap[COL_SEC].R = 0 ;
prj->backWin.cmap[COL_SEC].G = 100 ;
prj->backWin.cmap[COL_SEC].B = 200 ;
prj->backWin.cmap[COL_MIN].R = 255 ;
prj->backWin.cmap[COL_MIN].G = 0 ;
prj->backWin.cmap[COL_MIN].B = 0 ;
prj->backWin.cmap[COL_HEU].R = 0 ;
prj->backWin.cmap[COL_HEU].G = 255 ;
prj->backWin.cmap[COL_HEU].B = 0 ;
prj->backWin.cmap[COL_TIC].R = 0 ;
prj->backWin.cmap[COL_TIC].G = 0 ;
prj->backWin.cmap[COL_TIC].B = 255 ;
prj->backWin.cmap[COL_BAC].R = 0 ;
prj->backWin.cmap[COL_BAC].G = 0 ;
prj->backWin.cmap[COL_BAC].B = 0 ;
prj->backWin.cmap[COL_MPO].R = 0 ;
prj->backWin.cmap[COL_MPO].G = 0 ;
prj->backWin.cmap[COL_MPO].B = 0 ;
prj->backWin.cmap[COL_BLA].R = 0 ;
prj->backWin.cmap[COL_BLA].G = 0 ;
prj->backWin.cmap[COL_BLA].B = 0 ;
prj->backWin.fill = FALSE ;
prj->backWin.filln = TRUE ;
prj->backWin.drawsha = TRUE ;
prj->backWin.drawmpo = TRUE ;
if (file = Open("ENV:backclock.prefs", MODE_OLDFILE)) {
Read(file, &cf_load, 4) ;
if ((cf_load.id[0] == 'B') &&
(cf_load.id[1] == 'A') &&
(cf_load.id[2] == 'C') &&
(cf_load.id[3] == 'K')) {
Seek(file, 0, OFFSET_BEGINNING) ;
Read(file, &cf_load, sizeof(struct ConfFile)) ;
prj->backWin.posX = cf_load.posX ;
prj->backWin.posY = cf_load.posY ;
prj->backWin.width = cf_load.lenX ;
prj->backWin.height = cf_load.lenY ;
for(i = 0; i < NUM_COLORS; i++)
CopyMem(&(cf_load.cmap[i]), &(prj->backWin.cmap[i]), sizeof(struct RGB)) ;
prj->backWin.fill = (BOOL)cf_load.fill ;
prj->backWin.filln = cf_load.filln ;
prj->backWin.drawsec = cf_load.drawsec ;
prj->backWin.drawsha = cf_load.drawsha ;
prj->backWin.drawmpo = cf_load.drawmpo ;
initColors(prj) ;
ret = TRUE ;
prj->lastError = OK ;
}
Close(file) ;
}
return(ret) ;
}